<?php
class Training_Table2Controller extends Zend_Controller_Action{

	public function init() {
		parent::init();
		$this->_helper->layout->disableLayout();
		$this->_helper->viewRenderer->setNoRender();
	}
	
	public function indexAction() {
		echo "<br>" . __METHOD__;
		$tblGroup = new Training_Model_GroupMap();
		$id = 2;
		$rowSet = $tblGroup->find(4);
		$row2	= $rowSet->current();
		
		$userByGroup = $row2->findDependentRowset('Training_Model_UserMap');
		echo '<pre>';
		print_r($userByGroup->toArray());
		echo '</pre>';
	}
	
	public function index2Action() {
		$tblUser = new Training_Model_UserMap();
		$rows = $tblUser->find(1);
		$user1 = $rows->current();
		
		//Cach1
		//$acticleByUser = $user1->findDependentRowset('Training_Model_NewsArticle');
		//Cach2
		$acticleByUser = $user1->findTraining_Model_NewsArticle();
		
		echo '<pre>';
		print_r($acticleByUser);
		echo '</pre>';
	}
	
	public function index3Action() {
		$tblUser = new Training_Model_UserMap();
		$rows = $tblUser->find(1);
		$user1 = $rows->current();

		$select = $tblUser->select()
						  ->where('status = 0');
		$acticleByUser = $user1->findDependentRowset('Training_Model_NewsArticle', 'User_Modified', $select);
		
		echo '<pre>';
		print_r($acticleByUser);
		echo '</pre>';
	}
	
	public function index4Action() {
		$tblUser = new Training_Model_UserMap();
		$rows = $tblUser->find(1);
		$user1 = $rows->current();
		$select = $tblUser->select()
						  ->where('status = 0');
//		$acticleByUser = $user1->find<'class_of_children_table'>By<'rule_key'>();
		$acticleByUser = $user1->findTraining_Model_NewsArticleByUser_Modified();
		
		echo '<pre>';
		print_r($acticleByUser);
		echo '</pre>';
	}
	
	public function index5Action() {
		$tblUser = new Training_Model_UserMap();
		$rows = $tblUser->find(1);
		$user1 = $rows->current();
		$select = $tblUser->select()
						  ->from('news_article')
						  ->where('status = 1');
		$acticleByUser = $user1->findDependentRowset('Training_Model_NewsArticle', 'User_Poster', $select);
		
		echo '<pre>';
		print_r($acticleByUser);
		echo '</pre>';
	}
	
	public function index6Action() {
		$tblArticle = new Training_Model_NewsArticle();
		$articleRowset = $tblArticle->fetchAll(' id = 9');
		$article = $articleRowset->current();
		$select = $tblArticle->select()
							->where(" status = 1");
		
		$user = $article->findParentRow('Training_Model_UserMap', 'User_Modified', $select);
		echo '<pre>';
		print_r($user);
		echo '</pre>';
	}
	
		public function index7Action() {
		$tblArticle = new Training_Model_NewsArticle();
		$articleRowset = $tblArticle->fetchAll(' id = 9');
		$article = $articleRowset->current();
		
//		$user = $article->findParentRow('Training_Model_UserMap', 'User_Modified');
		$user = $article->findParentTraining_Model_UserMapByUser_Modified();
		echo '<pre>';
		print_r($user);
		echo '</pre>';
	}
	
	public function index8Action() {
		//Tim cac Category cua Article khi biet ID cua Article
		$tblArticle = new Training_Model_NewsArticle();
		$articleRowset = $tblArticle->fetchAll(' id = 1');
		$article = $articleRowset->current();
		
		//C1
		$categoryRowset = $article->findManyToManyRowset('Training_Model_NewsCategory', 
														'Training_Model_NewsCategoryArticle');
		//C2
		$categoryRowset = $article->findTraining_Model_NewsCategoryViaTraining_Model_NewsCategoryArticle();
		echo '<pre>';
		print_r($categoryRowset);
		echo '</pre>';
	}
		
	public function index9Action() {
		//Tim cac Category cua Article khi biet ID cua Article
		$tblCategory = new Training_Model_NewsCategory();
		$categoryRowset = $tblCategory->fetchAll(' id = 1');
		$category = $categoryRowset->current();
		$category->delete();
	}
	
	public function index10Action() {
		//Tim cac Category cua Article khi biet ID cua Article
		$tblArticle = new Training_Model_NewsArticle();
		$articleRowset = $tblArticle->fetchAll(' id = 4');
		$article = $articleRowset->current();
		$article->delete();
	}
	
}